﻿using HolterDatabase.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HolterDatabase.ViewModel
{
    public class HolterEntryViewModel : ViewModel
    {
        public HolterEntryViewModel(HolterEntry holterEntry)
        {
            this.holterEntry = holterEntry;
        }

        public string FirstName { get { return holterEntry.FirstName; } set { holterEntry.FirstName = value; OnPropertyChanged("FirstName"); IsDirty = true; } }
        public string LastName { get { return holterEntry.LastName; } set { holterEntry.LastName = value; OnPropertyChanged("LastName"); IsDirty = true; } }
        public System.DateTime? BirthDate { get { return holterEntry.BirthDate; } set { holterEntry.BirthDate = value; OnPropertyChanged("BirthDate"); IsDirty = true; } }
        public string Adress { get { return holterEntry.Adress; } set { holterEntry.Adress = value; OnPropertyChanged("Adress"); IsDirty = true; } }
        public string Phone { get { return holterEntry.Phone; } set { holterEntry.Phone = value; OnPropertyChanged("Phone"); IsDirty = true; } }
        public System.DateTime? OutDate { get { return holterEntry.OutDate; } set { holterEntry.OutDate = value; OnPropertyChanged("OutDate"); IsDirty = true; } }
        public System.TimeSpan? OutTime { get { return holterEntry.OutTime; } set { holterEntry.OutTime = value; OnPropertyChanged("OutTime"); IsDirty = true; } }
        public System.DateTime? PlayDate { get { return holterEntry.PlayDate; } set { holterEntry.PlayDate = value; OnPropertyChanged("PlayDate"); IsDirty = true; } }
        public string Indication { get { return holterEntry.Indication; } set { holterEntry.Indication = value; OnPropertyChanged("Indication"); IsDirty = true; } }
        public string Treatment { get { return holterEntry.Treatment; } set { holterEntry.Treatment = value; OnPropertyChanged("Treatment"); IsDirty = true; } }
        public string Comment { get { return holterEntry.Comment; } set { holterEntry.Comment = value; OnPropertyChanged("Comment"); IsDirty = true; } }
        public string Conclusion { get { return holterEntry.Conclusion; } set { holterEntry.Conclusion = value; OnPropertyChanged("Conclusion"); IsDirty = true; } }
        public string Doctor { get { return holterEntry.Doctor; } set { holterEntry.Doctor = value; OnPropertyChanged("Doctor"); IsDirty = true; } }
        public int HolterId { get { return holterEntry.HolterId; } set { holterEntry.HolterId = value; OnPropertyChanged("HolterId"); IsDirty = true; } }
        public int PatientId { get { return holterEntry.PatientId; } set { holterEntry.PatientId = value; OnPropertyChanged("PatientId"); IsDirty = true; } }
        public bool Payment { get { return holterEntry.Payment; } set { holterEntry.Payment = value; OnPropertyChanged("Payment"); IsDirty = true; } }
        public bool Validated { get { return holterEntry.Validated; } set { holterEntry.Validated = value; OnPropertyChanged("Validated"); IsDirty = true; } }
        public int Duration { get { return holterEntry.Duration; } set { holterEntry.Duration = value; OnPropertyChanged("Duration"); IsDirty = true; } }
        public System.DateTime? ReturnDate { get { return holterEntry.ReturnDate; } set { holterEntry.ReturnDate = value; OnPropertyChanged("ReturnDate"); IsDirty = true; } }
        public int ExamNumber { get { return holterEntry.ExamNumber; } set { holterEntry.ExamNumber = value; OnPropertyChanged("ExamNumber"); IsDirty = true; } }
        public bool Internal { get { return holterEntry.Internal; } set { holterEntry.Internal = value; OnPropertyChanged("Internal"); IsDirty = true; } }

        public HolterEntryViewModelMode Mode { get; set; }

        public void Save()
        {
            if (Mode == HolterEntryViewModelMode.Creation)
            {
                holterEntry.Insert();
            } 
            else
            {
                holterEntry.Update();
            }

            IsDirty = false;
        }

        private HolterEntry holterEntry;
    }

    public enum HolterEntryViewModelMode
    {
        Creation,
        Modification
    }
}
